package com.sjy.mvvmdemo.roomdb.db

import androidx.lifecycle.LiveData
import androidx.room.*

/**
 * 数据库操作
 */
@Dao
interface UserDao {
    @Insert
    suspend fun addUserData(user: UserEntity): Long

    @Insert
    fun addLists(users: List<UserEntity>)

    @Update
    suspend fun updateUserData(user: UserEntity): Int

    //等价用法
    @Query("update  sjy_user set user_name = :name where user_pass =  :ps")
    fun update(name: String, ps: String)

    @Delete
    suspend fun deletUser(user: UserEntity): Int

    //sqlite语句
    @Query("DELETE FROM sjy_user")
    suspend fun deleteAll(): Int

    @Query("SELECT * FROM sjy_user")
    fun getAllUserData(): LiveData<List<UserEntity>>

    /**
     * 查找姓名
     */
    @Query("SELECT * FROM sjy_user where user_name = :name")
    fun getUserById(name: String): UserEntity
}